package fido;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.net.URL;


public class FidoGUI extends JFrame {
    private JPanel panel1;
    public JTextField textUserName;
    public JRadioButton a1HoursRadioButton;
    public JRadioButton a3HoursRadioButton;
    public JRadioButton a12HoursRadioButton;
    public JRadioButton a24HoursRadioButton;
    public JRadioButton noTimerRadioButton;
    public JButton buttonRunNow;
    public ButtonGroup buttonGroup = new ButtonGroup();
    public JList lDownloadedMoviesList;
    public JPasswordField textPassword;
    private JScrollPane jScrollPane1;
    public JTextArea textArea2;
    public JList lWishList;
    private JButton checkVersionButton;
    public JButton buttonSelectDownloadLocation;
    public JLabel labelSelectedDownloadLocation;

    private JPanel panelLogin;
    private JPanel panelAutomaticDownload;
    public JProgressBar progressBar;
    public JPanel newPanel;
    public JPanel panelTrackers;
    private JButton btnAbout;
    public JPanel anotherPanel;


        Image fidoIcon = getImage();
    TrayIcon trayIcon = new TrayIcon(fidoIcon, "Fido");

    void buttonGroupListener(ActionListener bgl) {
        noTimerRadioButton.addActionListener(bgl);
        a1HoursRadioButton.addActionListener(bgl);
        a3HoursRadioButton.addActionListener(bgl);
        a12HoursRadioButton.addActionListener(bgl);
        a24HoursRadioButton.addActionListener(bgl);
    }

    void buttonCheckVersionListener(ActionListener listener) {
        checkVersionButton.addActionListener(listener);
    }

    FidoGUI() {
        setIconImage(fidoIcon);

        buttonGroup.add(noTimerRadioButton);
        buttonGroup.add(a1HoursRadioButton);
        buttonGroup.add(a3HoursRadioButton);
        buttonGroup.add(a12HoursRadioButton);
        buttonGroup.add(a24HoursRadioButton);

        this.setContentPane(panel1);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setResizable(false);

        this.pack();
        this.setTitle("Fido");


        //Start system tray
        if (SystemTray.isSupported()) {
            try {
                SystemTray.getSystemTray().add(trayIcon);
            } catch (AWTException e) {
                e.printStackTrace();
            }
        }

        btnAbout.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "Welcome to Fido\nFido is not apart of Mymediadb.org or any of the trackers listed in Fido,\n please don't use Fido to download copyrighted material. \n\nUse Fido at your own risk, and remember above else, \n         Enjoy life!!\n\nSource code can be found at\nhttp://code.google.com/p/fido/", "About Fido", 1);
            }
        });


    }

    private Image getImage() {
        try {
            URL myUrl = this.getClass().getResource("/dog-icon.png");
            Toolkit tk = this.getToolkit();

            return tk.getImage(myUrl);
        } catch (Exception e) {
            System.out.println("Didn't find image");
        }


        return null;
    }

}

